import Vue from 'vue'
import Loading from './loading.vue'

const Instance = Vue.extend(Loading)

const updateVisible = (instance, binding) => {
  instance.visible = binding.value
}

export default {
  bind: function(el, binding) {
    const instance = new Instance().$mount(document.createElement('div'))
    el.appendChild(instance.$el)
    el.instance = instance
    updateVisible(instance, binding)
  },
  update: function (el, binding) {
    updateVisible(el.instance, binding)
  },
  unbind: function (el) {
    el.instance && el.instance.$destroy()
  }
}